/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.geomagnetic_sensor_info.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.geomagnetic_sensor_info.entity.GeomagneticSensorInfo;
import com.thinkgem.jeesite.modules.geomagnetic_sensor_info.service.GeomagneticSensorInfoService;

/**
 * 传感器传送数据信息Controller
 * @author xlp
 * @version 2019-04-11
 */
@Controller
@RequestMapping(value = "${adminPath}/geomagnetic_sensor_info/geomagneticSensorInfo")
public class GeomagneticSensorInfoController extends BaseController {

	@Autowired
	private GeomagneticSensorInfoService geomagneticSensorInfoService;
	
	@ModelAttribute
	public GeomagneticSensorInfo get(@RequestParam(required=false) String id) {
		GeomagneticSensorInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = geomagneticSensorInfoService.get(id);
		}
		if (entity == null){
			entity = new GeomagneticSensorInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("geomagnetic_sensor_info:geomagneticSensorInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(GeomagneticSensorInfo geomagneticSensorInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<GeomagneticSensorInfo> page = geomagneticSensorInfoService.findPage(new Page<GeomagneticSensorInfo>(request, response), geomagneticSensorInfo); 
		model.addAttribute("page", page);
		return "modules/geomagnetic_sensor_info/geomagneticSensorInfoList";
	}

	@RequiresPermissions("geomagnetic_sensor_info:geomagneticSensorInfo:view")
	@RequestMapping(value = "form")
	public String form(GeomagneticSensorInfo geomagneticSensorInfo, Model model) {
		model.addAttribute("geomagneticSensorInfo", geomagneticSensorInfo);
		return "modules/geomagnetic_sensor_info/geomagneticSensorInfoForm";
	}

	@RequiresPermissions("geomagnetic_sensor_info:geomagneticSensorInfo:edit")
	@RequestMapping(value = "save")
	public String save(GeomagneticSensorInfo geomagneticSensorInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, geomagneticSensorInfo)){
			return form(geomagneticSensorInfo, model);
		}
		geomagneticSensorInfoService.save(geomagneticSensorInfo);
		addMessage(redirectAttributes, "保存传感器传送数据信息成功");
		return "redirect:"+Global.getAdminPath()+"/geomagnetic_sensor_info/geomagneticSensorInfo/?repage";
	}
	
	@RequiresPermissions("geomagnetic_sensor_info:geomagneticSensorInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(GeomagneticSensorInfo geomagneticSensorInfo, RedirectAttributes redirectAttributes) {
		geomagneticSensorInfoService.delete(geomagneticSensorInfo);
		addMessage(redirectAttributes, "删除传感器传送数据信息成功");
		return "redirect:"+Global.getAdminPath()+"/geomagnetic_sensor_info/geomagneticSensorInfo/?repage";
	}

}